
<form method="post" id="form1">
<table border="0" class="form">
<tr>
	<td colspan=2 class="head">添加分类交集</td>
</tr>
<tr>
	<td class="title">分类一</td>
	<td class="data">
<?php echo Html::options($cates, array('id'=>'root1','tips'=>'----',
			'ext'=>'onchange="express_cate(\'root1\',\'pid1\')"' )); ?>
<?php echo Html::options(array(), array('id'=>'pid1','name'=>'pid1')); ?>
	</td>
</tr>
<tr>
	<td class="title">分类二</td>
	<td class="data">
<?php echo Html::options($cates, array('id'=>'root2','tips'=>'----',
			'ext'=>'onchange="express_cate(\'root2\',\'pid2\',\'pid1\')"' )); ?>
<?php echo Html::options(array(), array('id'=>'pid2','name'=>'pid2')); ?>
	</td>
</tr>
<tr>
	<td class="title">类型</td>
	<td class="data">
		<input type="radio" name="type" value="0" id="type_0" checked /><label for="type_0">Whole</label>
		<input type="radio" name="type" value="1" id="type_1" /><label for="type_1">Selected</label>
	</td>
</tr>
<tr>
	<td class="title">交集分类</td>
	<td class="data">
<?php echo Html::options($mixes, array('id'=>'hid','name'=>'hid','tips'=>'----')); ?>
		<div id="vbox"></div>
	</td>
</tr>
<tr>
	<td colspan=2 class="foot">
		<input type="button" value="返回" onclick="location.href='<?php echo url('mix');?>'" /> &nbsp;
		<input type="submit" value="保存" />
	</td>
</tr>
</table>
</form>

<script>
$(document).ready(function(){
	$('#form1').ajaxForm(function(data){
		alert(data.message);
		if(data.level=='notice') location.href=data.jump?data.jump:'<?php echo $_SERVER['REQUEST_URI'] ?>';
	});
	$('input[name=type]').change(function(){
		$('#vbox input[type=checkbox]').attr('disabled', $('input[name=type]:checked').val()=='1'?false:true);
	});
	$('select[name=hid]').change(express_hid);
	express_hid();
});
function express_cate(root, pid, ref_id)
{
	$('#'+pid).html('');
	if(cate_id = $('#'+root).val())
	{
		load_ci(cate_id, function(data){
			ht	= '<option value="">----</option>';
			for(i in data.items)
			{
				ht	+= '<option value="'+data.items[i].hid+'">'+data.items[i].title+'</option>';
			}
			$('#'+pid).html(ht);
		}, ref_id?$('#'+ref_id).val():'' );
	}
}
function express_hid()
{
	$('#vbox').html('');
	if(hid = $('select[name=hid]').val())
	{
		load_ci(hid, function(data){
			ht	= '';
			ex	= '0'==$('input[name=type]:checked').val() ? ' disabled ':'';
			for(i in data.items)
			{
				ht	+= ' <nobr><input type="checkbox" name="value[]" '+ex+' value="'+data.items[i].hid
					+'" id="val_'+data.items[i].hid+'" align="center" /><label for="val_'+data.items[i].hid
					+'">'+data.items[i].title+'</label></nobr>&nbsp;';
			}
			$('#vbox').html(ht);
		});
	}
}
function load_ci(cate_id, func, ref_id)
{
	$.get('<?php echo url('mix-ci/id/ID/ref/REF') ?>'
		.replace('ID',cate_id)
		.replace('REF',ref_id?ref_id:'0'), func);
}
</script>
